package com.css.fxfzmhwz.zcpt.sys.controller;

import com.css.fxfzmhwz.base.response.RestResponse;
import com.css.fxfzmhwz.util.CreateGson;
import com.css.fxfzmhwz.zcpt.sys.service.SysRoleService;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Dbj
 * @date 2022年09月1日  18:00
 */
@RestController
@RequestMapping("/fxfz/sRole")
@Slf4j
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;
    /**
     * 获取全部组织机构树
     */
    @GetMapping("/getRoleByUserId")
    public RestResponse getRoleByUserId(@RequestParam("userId") String userId) {
        RestResponse restResponse = null;
        try{
            String jsonStr = sysRoleService.getRoleByUserId(userId);
            Gson gson = CreateGson.createGson();
            List sysMenuList = gson.fromJson(jsonStr, List.class);
            restResponse = RestResponse.succeed(sysMenuList);
        }catch (Exception e){
            log.error("查询角色失败!",e);
            restResponse = RestResponse.fail("查询角色失败!");
        }
        return restResponse;
    }
}
